/**
	@file branchy.S
	@author Andrew D. Zonenberg
	@brief Test of the conditional branch instructions
 */
 
.set noreorder					/*	Prevent any optimizations from reordering instructions!
									We want exe to exactly match source! */

.section .startup.bootvec, "ax", @progbits 
.globl _start
_start:
	
	/* Turn on first LED so we know all is well */
	la			$t7, LEDBANKA
	li			$t0, 1
	sw			$t0, 0($t7)
	
	/* DEADBEEF is negative, so not >= 0 and we shouldn't jump*/	
	li			$t0, 0xdeadbeef
	bgez		$t0, .error
	
	/* BGEZAL shouldn't jump either */
	bgezal		$t0, .error
	
	/* Neither should BGTZ */
	bgtz		$t0, .error
	
	/* but BLTZ should */
	bltz		$t0, .good1
	j			.error				/* If we don't jump, trigger error */
	
.good1:

	/* So should BLTZAL */
	li			$v0, 0				/*	If we return with $v0 != 0 then we jumped */
	bltzal		$t0, .good2
	beq			$v0, $zero, .error
	
	/* 1234 is positive so BGEZ should jump */
	li			$t0, 0x1234
	bgez		$t0, .good3
	j			.error
	
.good3:

	/* So should BGEZAL */
	bgezal		$t0, .good2
	beq			$v0, $zero, .error
	
	/* and BGTZ */
	bgtz		$t0, .good4
	j			.error
	
.good4:
							
	/* If we get here, turn on the second LED and say "pass" */
	la			$t7, LEDBANKASET
	li			$t0, 2
	sw			$t0, 0($t7)
				
.infloop:							/*	Infinite loop
										tests j instruction */
	j			.infloop
	
	/* Should never get here. Turn on highest LED to indicate error */
.error:
	la			$t7, LEDBANKASET
	li			$t0, 0x80
	sw			$t0, 0($t7)
	
	j			.infloop

.good2:
	li			$v0, 1
	jr			$ra
